package com.matrix.draft.algorithm;

import com.matrix.draft.algorithm.product.LinkNode;
import com.matrix.draft.algorithm.util.AlgoUtil;


/**
 * LeetCode206题: 反转链表
 */
public class L206 {

    public static void main(String[] args) {
        LinkNode head = AlgoUtil.makeALink(10);
        AlgoUtil.showLink(head, true);
        reverseLink(head);
        AlgoUtil.showLink(head, true);

    }

    static void reverseLink(LinkNode head) {
        if (null == head) {
            return;
        }
        LinkNode pre = null;
        LinkNode cur = head.next;
        LinkNode next = cur.next;
        while (next != null) {
            cur.next = pre;
            pre = cur;
            cur = next;
            next = next.next;
        }
        cur.next = pre;
        head.next = cur;
    }


}
